<?php
class edisiMod extends MY_Model{
	
	function __construct(){
		parent::__construct(
			'edisi',
			array(
				'id_edisi',
				'author',
				'ke',
				'images_large',
				'images_medium',
				'images_small',
				'images_type',
				'posted'
			),
			'id_edisi'
		);
	}
	
	function generateID($data){
		return do_hash($data.(unix_to_human(time(),true,'eu')."EdisiNewMod").$this->table_name);
	}
	
	function add($newData){
		$newData['posted'] = unix_to_human(time(),true,'eu');
		$this->db->insert($this->table_name, $newData);
	}
	
	function update($id,$newData){
		$newData['posted'] = unix_to_human(time(),true,'eu');
		$this->db->where($this->table_fields[0], $id);
		return $this->db->update($this->table_name, $newData);
	}
	
	function delete($ids){
		if (!is_array($ids)) $ids = array($ids);
    	foreach($ids as $pk) {
    		$this->db->or_where($this->table_fields[0], $pk);	
    	}    	
    	return $this->db->delete($this->table_name, $pk);
	}
    
	function remove($ids){
    	return $this->db->delete($this->table_name, array($this->table_fields[0]=>$ids));
    }
	
 	function get($id){
		return $this->db->get_where($this->table_name, array($this->table_fields[0]=>$id));
    }
    
	function get_record($limit,$offset){
		$this->db->order_by('posted','desc');
		$this->db->limit($offset,$limit);
		return $this->db->get($this->table_name);
    }
    
	function get_where($where,$limit=0,$offset=20){
//    	return $this->db->get_where($this->table_name, $where, $limit, $offset);
		$this->db->order_by('posted','desc');
    	return $this->db->get_where($this->table_name, $where);
    }
	
	
}